package net.alteiar.images;

import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import net.alteiar.images.filter.IFilter;

public class ImageFiltered extends IDrawable implements Observer {
	private final BasicImage background;
	private final ArrayList<IFilter> allLayers;

	public ImageFiltered(BasicImage img) {
		background = img;
		allLayers = new ArrayList<>();

		background.addObserver(this);
	}

	public void addImage(IFilter image) {
		image.addObserver(this);
		allLayers.add(image);

		this.setChanged();
		this.notifyObservers();
	}

	@Override
	public void draw(Graphics2D g2, double zoomFactor) {
		background.draw(g2, zoomFactor);
		for (IFilter im : allLayers) {
			im.draw(g2, zoomFactor);
		}
	}

	@Override
	public int getWidth() {
		return background.getWidth();
	}

	@Override
	public int getHeight() {
		return background.getHeight();
	}

	@Override
	public void update(Observable o, Object arg) {
		this.setChanged();
		this.notifyObservers();
	}
}
